<template>
  <basic-container>
    <el-tabs v-model="tabsIndex" @tab-click="handleTabClick(tabsIndex)" style="margin: 0 10px">
      <el-tab-pane label="物料类别" name="1"> </el-tab-pane>
      <el-tab-pane label="物料" name="2"> </el-tab-pane>
    </el-tabs>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      :before-close="beforeClose"
      :search.sync="search"
      v-model="form"
      :key="key"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @tree-load="treeLoad"
      @refresh-change="refreshChange"
      @expand-change="expandChange"
    >
      <template slot="Index" slot-scope="{ row }">
        {{ row.dataIndex }}
      </template>
      <template slot="menuLeft">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="small"
          v-if="form.objectType === 'PART_CATEGORY' && permission.iqcInspectionAttributes_add"
          plain
          @click.stop="configAttributes()"
          >批量配置检验属性</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="small"
          v-if="form.objectType === 'PART_CATEGORY' && permission.iqcInspectionAttributes_add"
          plain
          @click.stop="openGlobalConfigDialog()"
          >全局默认配置</el-button
        >
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" icon="el-icon-view" v-if="permission.iqcInspectionAttributes_detail" @click="handleDatail(scope.row)">详 情</el-button>
        <el-button type="text" size="small" icon="el-icon-edit" v-if="permission.iqcInspectionAttributes_edit" @click="handleEidt(scope.row)">编 辑</el-button>
        <el-button
          type="text"
          size="small"
          icon="el-icon-edit"
          v-if="(form.objectType === 'PART_MASTER' || form.objectType === 'PART_MASTER_VENDOR') && permission.iqcInspectionAttributes_partner"
          @click="handlePartner(scope.row)"
          >供应商</el-button
        >
      </template>
    </avue-crud>

    <el-dialog append-to-body :title="dialogTitle" v-if="showDialog" :visible.sync="showDialog" width="60%">
      <avue-form ref="attributeProperties" v-model="attributeModel" :option="attributeOption">
        <template slot="inspectionTemplateInfo">
          <el-button type="primary" v-if="!dialogTitle.includes('详情')" icon="el-icon-plus" size="small" plain @click.stop="addTemplate()">添加检验模板</el-button>
          <div style="display: flex; margin-top: 15px" v-for="(item, index) in inspectionTemplateList" :key="index">
            <el-input style="width: 400px" placeholder="请选择 检验模板" v-model="item.apaasTemplateName" class="input-with-select" disabled>
              <el-button slot="append" icon="el-icon-circle-close" v-if="item.apaasTemplateName" @click="resetTemplate(index)"></el-button>
              <el-button slot="append" icon="el-icon-search" @click="openInspectionTemplateModal(index)"></el-button>
            </el-input>
            <div style="display: flex; width: 180px; align-items: flex-start">
              <el-switch
                style="display: block; margin: 3px 0px 0px 30px"
                :disabled="dialogTitle.includes('详情')"
                v-model="item.isDefault"
                inactive-text="是否默认:"
                @change="handleSwitch(index, item.isDefault)"
              >
              </el-switch>
            </div>
            <el-button type="text" style="margin-right: 20px" @click="viewInspectionTemplate(item)">查看检验模板</el-button>
            <el-button type="text" :disabled="dialogTitle.includes('详情')" style="color: red" @click="deleteTemplate(index)">删除</el-button>
          </div>
        </template>
        <template slot="info">
          <avue-crud ref="infoCrud" :option="infoOption" :data="infoData" v-model="infoForm"> </avue-crud>
        </template>
        <!-- 供应商 -->
        <template slot="partnerInfo">
          <avue-crud
            ref="partnerCrud"
            @row-del="rowPartnerDel"
            @row-save="rowPartnerSave"
            @row-update="rowPartnerUpdate"
            :before-open="beforePartnerOpen"
            :option="partnerOption"
            :data="partnerData"
            v-model="partnerForm"
          >
            <template slot-scope="scope" slot="menu">
              <el-button type="text" size="small" v-if="permission.iqcInspectionAttributes_inspection_template" @click="partnerInspectionTemplate(scope.row)"
                >检验模板</el-button
              >
            </template>
          </avue-crud>
        </template>
      </avue-form>
      <div slot="footer" v-if="!attributeOption.detail">
        <el-button size="small" icon="el-icon-circle-close" @click="showDialog = false">取 消</el-button>
        <el-button size="small" icon="el-icon-circle-close" v-if="dialogTitle === '设置检验属性'" @click="showDialog = false">上一步</el-button>
        <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          v-if="attributeModel.objectType !== 'PART_MASTER_VENDOR'"
          @click="submitAttribute"
          v-preventReClick
          >保 存</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      ref="transferDialog"
      class="tranfer-dialog"
      title="选择物料类别"
      width="60%"
      append-to-body
      :visible.sync="transferDialog"
      @close="closeDialog()"
      :close-on-click-modal="false"
      v-if="transferDialog"
    >
      <div class="iqc-search-container" style="display: flex; flex-direction: row; width: 100%"></div>
      <el-row style="display: flex; flex-direction: row; width: 100%">
        <el-col :span="10">
          <avue-crud
            :key="timer"
            :option="transferOption"
            :page.sync="leftPage"
            :data="leftData"
            :table-loading="leftLoading"
            v-model="leftForm"
            ref="leftCrud"
            @search-change="searchLeftChange"
            @search-reset="searchLeftReset"
            @selection-change="selectionLeftChange"
            @current-change="currentLeftChange"
            @size-change="sizeLeftChange"
          >
            <template slot="menuLeft">
              <el-button type="text"><span class="title">物料类别列表：</span></el-button>
            </template>
          </avue-crud>
        </el-col>
        <el-col :span="4" style="display: flex; justify-content: center">
          <div class="el-transfer-button">
            <el-button type="primary" icon="el-icon-arrow-left" :disabled="rightSelectionList.length <= 0" class="btn" @click="moveToLeft"></el-button>
            <el-button type="primary" icon="el-icon-arrow-right" :disabled="leftSelectionList.length <= 0" class="btn" @click="moveToRight"></el-button>
          </div>
        </el-col>

        <el-col :span="10">
          <avue-crud :key="timer + 10000" :option="transferOption" :data="rightData" ref="rightCrud" @selection-change="selectionRightChange">
            <template slot="menuLeft">
              <el-button type="text"><span class="title">已选中列表：</span></el-button>
            </template>
          </avue-crud>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" icon="el-icon-circle-close" @click="transferDialog = false">取 消</el-button>
        <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="nextStep" :disabled="rightData.length === 0" v-preventReClick>下一步</el-button>
      </span>
    </el-dialog>
    <el-dialog append-to-body title="检验项明细" :visible.sync="showInspectionItemDialog" width="60%">
      <avue-crud :option="inspectionItemOption" v-model="inspectionItemModel" :data="inspectionItemData"> </avue-crud>
      <div slot="footer">
        <el-button size="small" icon="el-icon-circle-close" @click="showInspectionItemDialog = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog append-to-body title="供应商添加检验模板" :visible.sync="partnerInspectionTemDialog" width="60%">
      <avue-form ref="partnerInspectionTemProperties" :option="partnerInspectionTemOption">
        <template slot="inspectionTemplateInfo">
          <el-button type="primary" icon="el-icon-plus" size="small" plain @click.stop="addTemplate()">添加检验模板</el-button>
          <div style="display: flex; margin-top: 15px" v-for="(item, index) in inspectionTemplateList" :key="index">
            <el-input style="width: 400px" placeholder="请选择 检验模板" v-model="item.apaasTemplateName" class="input-with-select" disabled>
              <el-button slot="append" icon="el-icon-circle-close" v-if="item.apaasTemplateName" @click="resetTemplate(index)"></el-button>
              <el-button slot="append" icon="el-icon-search" @click="openInspectionTemplateModal(index)"></el-button>
            </el-input>
            <div style="display: flex; width: 180px; align-items: flex-start">
              <el-switch style="display: block; margin: 3px 0px 0px 30px" v-model="item.isDefault" inactive-text="是否默认:" @change="handleSwitch(index, item.isDefault)">
              </el-switch>
            </div>
            <el-button type="text" style="margin-right: 20px" @click="viewInspectionTemplate(item)">查看检验模板</el-button>
            <el-button type="text" style="color: red" @click="deleteTemplate(index)">删除</el-button>
          </div>
        </template>
      </avue-form>
      <div slot="footer">
        <el-button size="small" icon="el-icon-circle-close" @click="partnerInspectionTemDialog = false">取 消</el-button>
        <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="submitPartnerTemplate" v-preventReClick>保 存</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-if="apaasInspectionTemDialog"
      fullscreen
      append-to-body
      :modal-append-to-body="true"
      :close-on-click-modal="false"
      title="查看检验模板"
      :visible.sync="apaasInspectionTemDialog"
    >
      <apaas-template-preview :operateBtn="false" v-if="apaasInspectionTemDialog" ref="apaasTemplate"></apaas-template-preview>
    </el-dialog>

    <el-dialog append-to-body title="全局检验属性配置" v-if="globalConfigDialog" :visible.sync="globalConfigDialog" width="60%">
      <avue-form ref="globalConfigProperties" v-model="globalConfigModel" :option="globalConfigOption">
        <template slot="inspectionTemplateInfo">
          <div style="display: flex; margin-top: 15px">
            <el-input style="width: 400px" placeholder="请选择 检验模板" v-model="globalConfigModel.apaasTemplateName" class="input-with-select" disabled>
              <el-button slot="append" icon="el-icon-circle-close" v-if="globalConfigModel.apaasTemplateName" @click="resetTemplate('global')"></el-button>
              <el-button slot="append" icon="el-icon-search" @click="openInspectionTemplateModal('global')"></el-button>
            </el-input>
            <el-button type="text" style="margin-left: 20px" @click="viewInspectionTemplate(globalConfigModel)">查看检验模板</el-button>
          </div>
        </template>
      </avue-form>
      <div slot="footer">
        <el-button size="small" icon="el-icon-circle-close" @click="globalConfigDialog = false">取 消</el-button>
        <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="globalSubmitTemplate" v-preventReClick>保 存</el-button>
      </div>
    </el-dialog>
    <common-modal-template ref="commonModalTemplate" :option="tableOption" :key="timer" @getSelectedRows="getSelectedRows"></common-modal-template>
  </basic-container>
</template>

<script>
import { add, remove, submit, getSelectPage, getLazyList, getDetail, getAqlConfig, globalTemplate, globalSubmit } from '@/api/quality/iqc-inspection-attributes';
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';
import { mapGetters } from 'vuex';
import mixinFromInspectionAttributes from './mixins/fromInspectionAttributes';
import { getInspectionitemattributeList } from '@/api/quality/quality-manage';
import apaasTemplatePreview from '@/views/designer/preview';
export default {
  name: 'IqcInspectionAttributes',
  components: {
    CommonModalTemplate,
    userTableConfig,
    apaasTemplatePreview
  },
  mixins: [mixinFromInspectionAttributes, userConfig()],
  data() {
    return {
      pageCode: 'IQC_INSPECTION_ATTRIBUTES',
      form: {
        objectType: 'PART_CATEGORY'
      },
      globalConfigDialog: false,
      globalConfigModel: {},
      query: {},
      search: {},
      parentId: 0,
      tableOption: {},
      attributeModel: {},
      inspectionItemModel: {},
      templateModel: {},
      tabsIndex: '1',
      loading: true,
      leftLoading: true,
      templateDialog: false,
      showInspectionItemDialog: false,
      partnerInspectionTemDialog: false,
      apaasInspectionTemDialog: false,
      templateFlag: '',
      inspectionTemplateList: [
        {
          apaasTemplateId: '',
          apaasTemplateCode: '',
          apaasTemplateName: '',
          isDefault: false
        }
      ],
      tableOptionCopy: {},
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      leftPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      infoForm: {},
      leftForm: {},
      rightForm: {},
      partnerForm: {},
      selectionList: [],
      leftSelectionList: [],
      rightSelectionList: [],
      aqlConfigList: [],
      inspectionItemData: [],
      data: [],
      leftData: [],
      rightData: [],
      infoData: [],
      partnerData: [],
      inspectionPartConfigVOList: [],
      treeParams: new Map(), //懒加载参数
      showDialog: false,
      transferDialog: false,
      dialogTitle: '',
      key: new Date().getTime() + 100000,
      timer: new Date().getTime()
    };
  },
  watch: {},
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.iqcInspectionAttributes_add, false),
        viewBtn: this.vaildData(this.permission.iqcInspectionAttributes_view, false),
        editBtn: this.vaildData(this.permission.iqcInspectionAttributes_edit, false)
      };
    }
  },
  mounted() {
    this.option.index = false;
    this.option.column = this.categoryColumn;
    this.newKeyCrud();
    this.getAqlList();
    this.onLoad(this.page, { objectType: 'PART_CATEGORY' });
    this.$nextTick(() => {
      //搜索与表格结构分隔
      this.$structuralSplit();
    });
  },
  methods: {
    globalSubmitTemplate() {
      globalSubmit({
        inspectionType: 'IQC',
        apaasTemplateId: this.globalConfigModel.apaasTemplateId,
        apaasTemplateCode: this.globalConfigModel.apaasTemplateCode,
        apaasTemplateName: this.globalConfigModel.apaasTemplateName,
        aqlSchemeId: this.globalConfigModel.aqlSchemeId,
        aqlSchemeCode: this.globalConfigModel.aqlSchemeCode,
        aqlSchemeName: this.globalConfigModel.aqlSchemeName,
        minSamplingQuantity: this.globalConfigModel.minSamplingQuantity,
        inspectionMode: this.globalConfigModel.inspectionMode
      }).then((res) => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.globalConfigModel = {};
        this.globalConfigDialog = false;
      });
    },
    openGlobalConfigDialog() {
      globalTemplate({
        inspectionType: 'IQC'
      }).then((res) => {
        let data = res.data.data;
        this.globalConfigModel = { ...data, ...data.aqlScheme };
      });
      this.globalConfigDialog = true;
    },
    partnerInspectionTemplate(row) {
      this.partnerForm = row;
      this.inspectionTemplateList = this._cloneDeep(this.partnerForm.apaasTemplateJson);
      this.partnerInspectionTemDialog = true;
    },
    addTemplate() {
      this.inspectionTemplateList.push({
        apaasTemplateId: '',
        apaasTemplateCode: '',
        apaasTemplateName: '',
        isDefault: false
      });
    },
    deleteTemplate(index) {
      this.inspectionTemplateList.splice(index, 1);
    },
    handleSwitch(index, value) {
      this._forEach(this.inspectionTemplateList, (item, idx) => {
        if (idx === index && value) {
          item.isDefault = true;
        } else {
          item.isDefault = false;
        }
      });
    },
    viewInspectionTemplate(item) {
      if (!item.apaasTemplateId) {
        this.$message({
          type: 'warning',
          message: '请选择模版!'
        });
        return;
      }
      this.apaasInspectionTemDialog = true;
      this.$nextTick(() => {
        console.log(this.$refs.apaasTemplate, 'this.$refs.apaasTemplate');
        this.$refs.apaasTemplate.viewApaasTemplate(item.apaasTemplateId, false);
      });
      // this.$router.push({ path: '/designer/preview', query: { id: item.apaasTemplateId } });
    },
    /**
     * 检验模板模态框
     */
    openInspectionTemplateModal(index) {
      this.$refs.commonModalTemplate.showModal();
      this.tableOptionCopy.modalTitle = '选择检验模板（双击进行选择）';
      this.tableOptionCopy.url = '/api/mes-qms/apaas-template/page?type=IQC';
      this.tableOptionCopy.titleInfo = index;
      this.modalName = 'inspectionTemplateInfo';
      this.tableOption = this.tableOptionCopy;
    },
    resetTemplate(index) {
      if (index === 'global') {
        this.globalConfigModel.apaasTemplateId = '';
        this.globalConfigModel.apaasTemplateName = '';
        this.globalConfigModel.apaasTemplateCode = '';
        this.globalConfigModel.apaasTemplateJson = '';
      } else {
        this.inspectionTemplateList[index].apaasTemplateId = '';
        this.inspectionTemplateList[index].apaasTemplateName = '';
        this.inspectionTemplateList[index].apaasTemplateCode = '';
      }
    },
    viewInspectionItem(type, templateInfo) {
      console.log(templateInfo, 'templateInfo');
      if (!templateInfo.inspectionTemplateId) {
        this.$message({
          type: 'warning',
          message: '请选择模板!'
        });
        return;
      }
      getInspectionitemattributeList({
        inspectionTemplateId: templateInfo.inspectionTemplateId,
        objectId: templateInfo.objectId
      }).then((result) => {
        this.inspectionItemData = (result.data.data || []).map((item, index) => {
          return item;
        });
        this.showInspectionItemDialog = true;
      });
    },
    // submitTemplate() {
    //   this.$refs.templateProperties.validate((valid, done) => {
    //     if (valid) {
    //       if (this.templateFlag === 'PARTNER') {
    //         this.addPartnerRequest();
    //       } else {
    //         this.submitRequest();
    //       }
    //       this.templateDialog = false;
    //     }
    //   });
    // },
    // configTemplate(row, title) {
    //   this.templateFlag = title;
    //   if (this.templateFlag !== 'PARTNER') {
    //     this.detailRequst(row);
    //   } else {
    //     this.partnerForm = row;
    //     this.attributeModel.inspectionTemplateName = row.inspectionTemplateName;
    //     this.attributeModel.inspectionTemplateId = row.inspectionTemplateId;
    //     this.attributeModel.inspectionTemplateCode = row.inspectionTemplateCode;
    //   }
    //   this.templateDialog = true;
    // },
    submitPartnerTemplate() {
      let flag = this.inspectionTemplateList.some((item) => item.isDefault && item.apaasTemplateId);
      if ((this.partnerForm.inspectionMode === 'SAMPLING' || this.partnerForm.inspectionMode === 'FULLINSPECTION') && !flag) {
        this.$message({
          type: 'warning',
          message: `抽样方式为${this.partnerForm.aqlSchemeCode}（抽检或全检），检验模板需配置！`
        });
        return;
      }
      this.addPartnerRequest();
      this.partnerInspectionTemDialog = false;
    },
    resetQcTemplate() {
      this.attributeModel.inspectionTemplateName = '';
      this.attributeModel.inspectionTemplateId = '';
      this.attributeModel.inspectionTemplateCode = '';
    },
    searchReset() {
      this.query = {};
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    getAqlList() {
      getAqlConfig().then((res) => {
        let data = res.data.data;
        this.aqlConfigList = data;
      });
    },
    configAttributes() {
      this.leftData = [];
      this.rightData = [];
      this.leftPage = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      this.dialogTitle = '设置检验属性';
      this.onLeftLoad(this.leftPage);
      this.transferDialog = true;
      this.$nextTick(() => {
        let searchEls = document.querySelectorAll('.tranfer-dialog .avue-crud__search');
        let searchContainer = document.querySelector('.iqc-search-container');
        searchEls.forEach((ele, index) => {
          console.log(index === 0, index, 888, searchEls.length);
          if (index === 0) {
            searchContainer.append(ele);
          } else {
            ele.style.display = 'none';
          }
        });
      });
    },
    handleTabClick(tabIdx) {
      this.newKeyCrud();
      this.$nextTick(() => {
        this.$structuralSplit();
      });
      this.query = {};
      this.search = {};
      if (tabIdx == '1') {
        this.option.index = false;
        this.option.column = this.categoryColumn;
        this.form.objectType = 'PART_CATEGORY';
        this.onLoad(this.page, { objectType: 'PART_CATEGORY' });
      } else {
        this.option.index = true;
        this.option.column = this.partColumn;
        this.form.objectType = 'PART_MASTER';
        this.page = {
          pageSize: 20,
          currentPage: 1,
          total: 0
        };
        this.onLoad(this.page, { objectType: 'PART_MASTER' });
      }
    },
    selectionLeftChange(list) {
      this.leftSelectionList = list;
    },
    selectionRightChange(list) {
      this.rightSelectionList = list;
    },
    /*
     * 移至左边
     */
    moveToLeft() {
      this.rightData = this._differenceWith(this.rightData, this.rightSelectionList, (item1, item2) => {
        return item1.objectNo === item2.objectNo && item1.objectName === item2.objectName;
      });
      this.selectionClear();
    },
    /*
     * 移至右边
     */
    moveToRight() {
      let flag = false;
      this._uniqWith(this.leftSelectionList.concat(this.rightData), (arrVal, othVal) => {
        if (arrVal.objectNo === othVal.objectNo && arrVal.objectName === othVal.objectName) {
          flag = true;
        }
      });

      if (flag) {
        this.$message({
          type: 'warning',
          message: '当前和已选有重复，请重新选择!'
        });
        return;
      }
      this.rightData = this.rightData.concat(this.leftSelectionList);
      this.selectionClear();
    },
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        getDetail({
          id: this.form.id,
          objectType: 'PART_MASTER'
        }).then((res) => {
          this.attributeModel = res.data.data;
        });
        done();
      }
    },
    beforePartnerOpen(done, type) {
      if (['add'].includes(type)) {
        this.partnerForm.objectNo = this.attributeModel.objectNo;
        this.partnerForm.objectName = this.attributeModel.objectName;
        done();
      }
      if (['edit'].includes(type)) {
        done();
      }
    },
    resetAllForm() {
      this.attributeModel = {};
      this.partnerForm = {};
      this.inspectionTemplateList = [
        {
          apaasTemplateId: '',
          apaasTemplateCode: '',
          apaasTemplateName: '',
          isDefault: false
        }
      ];
    },
    resetAqlForm() {
      this.attributeModel.minSamplingQuantity = '';
      this.attributeModel.aqlSchemeCode = '';
      this.attributeModel.aqlSchemeName = '';
      this.attributeModel.aqlSchemeId = '';
      this.attributeModel.samplingStandard = '';
      this.attributeModel.severityCode = '';
      this.attributeModel.levelType = '';
      this.attributeModel.levelCode = '';
      this.attributeModel.limitCode = '';
      this.attributeModel.severityLimitCode = '';
      this.attributeModel.majorLimitCode = '';
      this.attributeModel.minorLimitCode = '';
    },
    resetPartnerAqlForm() {
      this.partnerForm.minSamplingQuantity = '';
      this.partnerForm.aqlSchemeCode = '';
      this.partnerForm.aqlSchemeName = '';
      this.partnerForm.aqlSchemeId = '';
      this.partnerForm.samplingStandard = '';
      this.partnerForm.severityCode = '';
      this.partnerForm.levelType = '';
      this.partnerForm.levelCode = '';
      this.partnerForm.limitCode = '';
      this.partnerForm.severityLimitCode = '';
      this.partnerForm.majorLimitCode = '';
      this.partnerForm.minorLimitCode = '';
    },
    resetGlobalAqlForm() {
      this.globalConfigModel.minSamplingQuantity = '';
      this.globalConfigModel.aqlSchemeCode = '';
      this.globalConfigModel.aqlSchemeName = '';
      this.globalConfigModel.aqlSchemeId = '';
      this.globalConfigModel.samplingStandard = '';
      this.globalConfigModel.severityCode = '';
      this.globalConfigModel.levelType = '';
      this.globalConfigModel.levelCode = '';
      this.globalConfigModel.limitCode = '';
      this.globalConfigModel.severityLimitCode = '';
      this.globalConfigModel.majorLimitCode = '';
      this.globalConfigModel.minorLimitCode = '';
    },
    submit() {},
    nextStep() {
      this.resetAllForm();
      this.handleFormToggle('PART_CATEGORY');
      this.dialogTitle = '设置检验属性';
      this.attributeOption.detail = false;
      this.showDialog = true;
      this.infoData = this._cloneDeep(this.rightData);
      this.inspectionPartConfigVOList = this.infoData.map((item) => {
        return {
          id: this.form.id,
          objectType: 'PART_CATEGORY',
          objectNo: item.objectNo,
          objectName: item.objectName,
          objectId: item.objectId,
          remark: item.remark
        };
      });
    },
    submitAttribute() {
      let flag = this.inspectionTemplateList.some((item) => item.isDefault && item.apaasTemplateId);
      if ((this.attributeModel.inspectionMode === 'SAMPLING' || this.attributeModel.inspectionMode === 'FULLINSPECTION') && !flag) {
        this.$message({
          type: 'warning',
          message: `抽样方式为${this.attributeModel.aqlSchemeCode}（抽检或全检），检验模板需配置！`
        });
        return;
      }
      this.$refs.attributeProperties.validate((valid, done) => {
        if (valid) {
          this.submitRequest();
          done();
        }
      });
      this.leftPage = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
    },
    //类别和物料
    submitRequest() {
      this.inspectionTemplateList.forEach((item) => {
        if (item.isDefault) {
          this.attributeModel.apaasTemplateName = item.apaasTemplateName;
          this.attributeModel.apaasTemplateId = item.apaasTemplateId;
          this.attributeModel.apaasTemplateCode = item.apaasTemplateCode;
        }
      });
      let params = {
        objectType: this.form.objectType,
        inspectionType: 'IQC',
        inspectionPartCommonVO: {
          inspectionMode: this.attributeModel.inspectionMode,
          minSamplingQuantity: this.attributeModel.minSamplingQuantity,
          aqlSchemeId: this.attributeModel.aqlSchemeId,
          aqlSchemeCode: this.attributeModel.aqlSchemeCode,
          aqlSchemeName: this.attributeModel.aqlSchemeName,
          principal: this.attributeModel.principal,
          principalName: this.attributeModel.principalName,
          inspectionTemplateName: this.attributeModel.inspectionTemplateName,
          inspectionTemplateId: this.attributeModel.inspectionTemplateId,
          inspectionTemplateCode: this.attributeModel.inspectionTemplateCode,
          apaasTemplateId: this.attributeModel.apaasTemplateId,
          apaasTemplateCode: this.attributeModel.apaasTemplateCode,
          apaasTemplateName: this.attributeModel.apaasTemplateName,
          apaasTemplateJson: JSON.stringify(this.inspectionTemplateList.filter((item) => item.apaasTemplateId))
        },
        inspectionPartConfigVOList: this._cloneDeep(this.inspectionPartConfigVOList)
      };
      add(params).then((res) => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.onLoad(this.page);
        this.showDialog = false;
        this.transferDialog = false;
        this.$refs.attributeProperties.resetForm();
      });
    },
    addPartnerRequest() {
      this.inspectionTemplateList.forEach((item) => {
        if (item.isDefault) {
          this.partnerForm.apaasTemplateName = item.apaasTemplateName;
          this.partnerForm.apaasTemplateId = item.apaasTemplateId;
          this.partnerForm.apaasTemplateCode = item.apaasTemplateCode;
        }
      });
      let params = {
        objectType: 'PART_MASTER_VENDOR',
        inspectionType: 'IQC',
        inspectionPartCommonVO: {
          id: this.partnerForm.id,
          vendorId: this.partnerForm.vendorId,
          vendorCode: this.partnerForm.vendorCode,
          vendorName: this.partnerForm.vendorName,
          inspectionMode: this.partnerForm.inspectionMode,
          aqlSchemeId: this.partnerForm.aqlSchemeId,
          aqlSchemeCode: this.partnerForm.aqlSchemeCode,
          aqlSchemeName: this.partnerForm.aqlSchemeName,
          inspectionTemplateName: this.attributeModel.inspectionTemplateName,
          inspectionTemplateId: this.attributeModel.inspectionTemplateId,
          inspectionTemplateCode: this.attributeModel.inspectionTemplateCode,
          apaasTemplateName: this.partnerForm.apaasTemplateName,
          apaasTemplateId: this.partnerForm.apaasTemplateId,
          apaasTemplateCode: this.partnerForm.apaasTemplateCode,
          apaasTemplateJson: JSON.stringify(this.inspectionTemplateList.filter((item) => item.apaasTemplateId))
        },
        inspectionPartConfigVOList: this._cloneDeep(this.inspectionPartConfigVOList)
      };
      submit(params).then((res) => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.detailRequst({
          objectId: this.attributeModel.objectId,
          objectType: 'PART_MASTER_VENDOR'
        });
      });
    },
    handlePartner(row) {
      this.resetAllForm();
      this.attributeOption.detail = false;
      this.attributeModel = {
        objectName: row.objectName,
        objectNo: row.objectNo,
        partType: row.partType,
        objectId: row.id
      };
      this.partnerForm.objectType = 'PART_MASTER_VENDOR';
      this.dialogTitle = '编辑供应商检验属性';
      this.handleFormToggle('PART_MASTER_VENDOR');
      this.detailRequst({
        objectId: row.objectId,
        objectType: 'PART_MASTER_VENDOR'
      });
      this.showDialog = true;
    },
    handleDatail(row) {
      this.dialogTitle = '检验属性详情';
      this.attributeOption.detail = true;
      this.handleFormToggle(row.objectType);
      this.detailRequst(row);
      this.showDialog = true;
    },
    handleEidt(row) {
      this.resetAllForm();
      this.dialogTitle = '编辑检验属性';
      this.attributeOption.detail = false;
      this.handleFormToggle(row.objectType);
      this.detailRequst(row);
      this.showDialog = true;
    },
    detailRequst(row) {
      getDetail({
        id: row.id,
        objectId: row.objectId,
        objectType: row.objectType,
        inspectionType: 'IQC'
      }).then((res) => {
        let data = res.data.data || {};
        let object = {
          PART_CATEGORY: 'handlePartCategory',
          PART_MASTER: 'handlePartMaster',
          PART_MASTER_VENDOR: 'handlePartVendor'
        };
        this[object[row.objectType]](data);
        this.inspectionPartConfigVOList = [data];
      });
    },
    handlePartCategory(data) {
      let inspectionPartVOList = data.inspectionPartVOList || [];
      if (inspectionPartVOList.length === 1) {
        this._forEach(inspectionPartVOList, (item) => {
          this.attributeModel = {
            ...(item.aqlScheme || {}),
            ...item,
            apaasTemplateJson:
              typeof item.apaasTemplateJson === 'string'
                ? JSON.parse(item.apaasTemplateJson)
                : [
                    {
                      apaasTemplateId: '',
                      apaasTemplateCode: '',
                      apaasTemplateName: '',
                      isDefault: false
                    }
                  ]
          };
          this.inspectionTemplateList = this.attributeModel.apaasTemplateJson;
        });
      } else {
        this.attributeModel = data;
      }
    },
    handlePartMaster(data) {
      let inspectionPartVOList = data.inspectionPartVOList || [];
      if (inspectionPartVOList.length === 1) {
        this._forEach(inspectionPartVOList, (item) => {
          this.attributeModel = {
            ...(item.aqlScheme || {}),
            ...item,
            apaasTemplateJson:
              typeof item.apaasTemplateJson === 'string'
                ? JSON.parse(item.apaasTemplateJson)
                : [
                    {
                      apaasTemplateId: '',
                      apaasTemplateCode: '',
                      apaasTemplateName: '',
                      isDefault: false
                    }
                  ]
          };
          this.inspectionTemplateList = this.attributeModel.apaasTemplateJson;
        });
      } else {
        this.attributeModel = data;
      }
    },
    handlePartVendor(data) {
      let inspectionPartVOList = data.inspectionPartVOList || [];
      this.partnerData = this._map(inspectionPartVOList, (item) => {
        return {
          ...(item.aqlScheme || {}),
          ...item,
          apaasTemplateJson:
            typeof item.apaasTemplateJson === 'string'
              ? JSON.parse(item.apaasTemplateJson)
              : [
                  {
                    apaasTemplateId: '',
                    apaasTemplateCode: '',
                    apaasTemplateName: '',
                    isDefault: false
                  }
                ]
        };
      });
      this;
      this.attributeModel = data;
    },
    handleFormToggle(objectType) {
      let partInfo = this.findNode(this.attributeOption.group, 'partInfo');
      let partCategoryName = this.findNode(partInfo.column, 'partCategoryName');
      let partObjectNo = this.findNode(partInfo.column, 'objectNo');
      let partObjectName = this.findNode(partInfo.column, 'objectName');
      let inspectionInfo = this.findNode(this.attributeOption.group, 'inspectionInfo');

      let samplingInfo = this.findNode(this.attributeOption.group, 'samplingInfo');
      let baseInfo = this.findNode(this.attributeOption.group, 'baseInfo');

      let partCategoryInfo = this.findNode(this.attributeOption.group, 'partCategoryInfo');
      let objectNo = this.findObject(baseInfo.column, 'objectNo');
      let objectName = this.findObject(baseInfo.column, 'objectName');
      let inspectionConfigInfo = this.findNode(this.attributeOption.group, 'inspectionConfigInfo');

      if (objectType === 'PART_CATEGORY') {
        objectNo.display = false;
        objectName.display = false;
        baseInfo.display = true;
        partCategoryInfo.display = false;
        partInfo.display = true;
        partCategoryName.display = false;
        partObjectNo.label = '物料类别编码';
        partObjectName.label = '物料类别名称';
        inspectionConfigInfo.display = false;
        samplingInfo.display = true;
        if (this.dialogTitle === '设置检验属性') {
          partInfo.display = false;
          partCategoryInfo.display = true;
        }
        inspectionInfo.display = true;
      } else if (objectType === 'PART_MASTER') {
        objectNo.display = false;
        objectName.display = false;
        partInfo.display = true;
        partCategoryName.display = true;
        partObjectNo.label = '物料编码';
        partObjectName.label = '物料名称';
        baseInfo.display = true;
        samplingInfo.display = true;
        partCategoryInfo.display = false;
        inspectionConfigInfo.display = false;
        inspectionInfo.display = true;
      } else if (objectType === 'PART_MASTER_VENDOR') {
        //PART_MASTER_VENDOR
        partInfo.display = true;
        partCategoryName.display = false;
        partObjectNo.label = '物料编码';
        partObjectName.label = '物料名称';
        baseInfo.display = false;
        samplingInfo.display = false;
        partCategoryInfo.display = false;
        inspectionConfigInfo.display = true;
        inspectionInfo.display = false;
        console.log(samplingInfo, 999);
      }
    },
    expandChange(row, expanded) {
      this.handleTreeDataIndex(row, expanded);
    },
    handleTreeDataIndex(row, checkStatus) {
      if (row.children && row.children.length > 0) {
        row.children.map((d, i) => {
          if (checkStatus) {
            d.dataIndex = row.dataIndex + '-' + (i + 1);
          }
        });
      }
    },
    handleAddSub(row) {
      this.dialogTitle = '新增子项';
      this.parentId = row.id;
      const column = this.findObject(this.basicPropertiesOption.column, 'parentId');
      column.value = row.id;
      column.addDisabled = true;
      this.showDialog = true;
    },

    findNode(list = [], prop) {
      let node;
      list.forEach((ele) => {
        if (ele.prop === prop) node = ele;
      });
      return node;
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.query);
    },
    currentLeftChange(currentPage) {
      this.leftPage.currentPage = currentPage;
      this.onLeftLoad(this.leftPage);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page, this.query);
    },
    sizeLeftChange(pageSize) {
      this.leftPage.pageSize = pageSize;
      this.onLeftLoad(this.leftPage);
    },
    searchLeftChange(params, done) {
      this.page.currentPage = 1;
      this.onLeftLoad(this.leftPage, params);
      done();
    },
    searchLeftReset() {
      this.page.currentPage = 1;
      this.onLeftLoad(this.leftPage, {});
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    selectionLeftRightClear() {
      this.leftSelectionList = [];
      this.rightSelectionList = [];
    },
    onLoad(page, params = {}) {
      params.objectType = this.form.objectType;
      params.inspectionType = 'IQC';
      if (this.form.objectType === 'PART_CATEGORY') {
        this.onLoadRequest(page, params);
        this.treeParams = new Map();
      } else {
        this.onLoadRequest(page, params);
      }
    },
    onLoadRequest(page, params = {}) {
      this.loading = true;
      params.objectType = this.form.objectType;
      getLazyList(this.parentId, page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data =
          res.data.data &&
          res.data.data.records &&
          res.data.data.records.map((item, index) => {
            item.dataIndex = index + 1;
            if (!item.id) item.id = item.objectId;
            return item;
          });
        this.page.total = res.data.data.total;
        this.data = data;
        this.loading = false;
        this.selectionClear();
      });
    },
    onLeftLoad(page, params = {}) {
      this.leftLoading = true;
      params.objectType = 'PART_CATEGORY';
      params.inspectionType = 'IQC';
      getSelectPage(page.currentPage, page.pageSize, params).then((res) => {
        const data = res.data.data;
        this.leftPage.total = data.total;
        this.leftData = data.records || [];
        this.leftLoading = false;
        this.selectionLeftRightClear();
      });
    },
    treeLoad(tree, treeNode, resolve) {
      const objectId = tree.objectId;
      const objectType = tree.objectType;
      this.treeParams.set(objectId, { tree, treeNode, resolve });
      console.log(this.treeParams, 'this.treeParams');
      getLazyList(objectId, null, null, {
        objectType,
        inspectionType: 'IQC'
      }).then((res) => {
        let data = res.data.data;
        if (data) {
          this._forEach(data.records, (item) => {
            if (!item.id) item.id = item.objectId;
          });
          resolve(data.records || []);
        } else {
          resolve([]);
        }
      });
    },
    closeDialog() {
      this.model = {};
      this.tabsIndex = '1';
      this.showDialog = false;
    },
    rowPartnerSave(row, done, loading) {
      this.addPartnerRequest();
      done();
      loading();
    },
    rowPartnerUpdate(row, index, done, loading) {
      this.addPartnerRequest();
      done();
    },

    rowPartnerDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.detailRequst(this.attributeModel);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    newKey() {
      this.timer = new Date().getTime();
    },
    newKeyCrud() {
      this.key = new Date().getTime() + 100000;
    },
    getSelectedRows(rowData, title) {
      switch (this.modalName) {
        case 'userModal':
          if (title === 'searchSelect') {
            this.search.principalName = this._get(rowData, 'name', '');
          } else {
            this.attributeModel.principal = this._get(rowData, 'id', '');
            this.attributeModel.principalName = this._get(rowData, 'name', '');
          }
          break;
        case 'aqlModal':
          if (title === 'partnerSelect') {
            this.partnerForm.aqlSchemeCode = this._get(rowData, 'code', '');
            this.partnerForm.aqlSchemeName = this._get(rowData, 'name', '');
            this.partnerForm.aqlSchemeId = this._get(rowData, 'id', '');
            this.partnerForm.samplingStandard = this._get(rowData, 'samplingStandard', '');
            this.partnerForm.severityCode = this._get(rowData, 'severityCode', '');
            this.partnerForm.levelType = this._get(rowData, 'levelType', '');
            this.partnerForm.limitCode = this._get(rowData, 'limitCode', '');
            this.partnerForm.levelCode = this._get(rowData, 'levelCode', '');
            this.partnerForm.severityLimitCode = this._get(rowData, 'severityLimitCode', '');
            this.partnerForm.majorLimitCode = this._get(rowData, 'majorLimitCode', '');
            this.partnerForm.minorLimitCode = this._get(rowData, 'minorLimitCode', '');
          } else if (title === 'globalConfig') {
            this.globalConfigModel.aqlSchemeCode = this._get(rowData, 'code', '');
            this.globalConfigModel.aqlSchemeName = this._get(rowData, 'name', '');
            this.globalConfigModel.aqlSchemeId = this._get(rowData, 'id', '');
            this.globalConfigModel.samplingStandard = this._get(rowData, 'samplingStandard', '');
            this.globalConfigModel.severityCode = this._get(rowData, 'severityCode', '');
            this.globalConfigModel.levelType = this._get(rowData, 'levelType', '');
            this.globalConfigModel.limitCode = this._get(rowData, 'limitCode', '');
            this.globalConfigModel.levelCode = this._get(rowData, 'levelCode', '');
            this.globalConfigModel.severityLimitCode = this._get(rowData, 'severityLimitCode', '');
            this.globalConfigModel.majorLimitCode = this._get(rowData, 'majorLimitCode', '');
            this.globalConfigModel.minorLimitCode = this._get(rowData, 'minorLimitCode', '');
          } else {
            this.attributeModel.aqlSchemeCode = this._get(rowData, 'code', '');
            this.attributeModel.aqlSchemeName = this._get(rowData, 'name', '');
            this.attributeModel.aqlSchemeId = this._get(rowData, 'id', '');
            this.attributeModel.samplingStandard = this._get(rowData, 'samplingStandard', '');
            this.attributeModel.severityCode = this._get(rowData, 'severityCode', '');
            this.attributeModel.levelType = this._get(rowData, 'levelType', '');
            this.attributeModel.limitCode = this._get(rowData, 'limitCode', '');
            this.attributeModel.levelCode = this._get(rowData, 'levelCode', '');
            this.attributeModel.severityLimitCode = this._get(rowData, 'severityLimitCode', '');
            this.attributeModel.majorLimitCode = this._get(rowData, 'majorLimitCode', '');
            this.attributeModel.minorLimitCode = this._get(rowData, 'minorLimitCode', '');
          }
          break;
        case 'partnerModal':
          this.partnerForm.vendorCode = this._get(rowData, 'code', '');
          this.partnerForm.vendorName = this._get(rowData, 'name', '');
          this.partnerForm.vendorId = this._get(rowData, 'id', '');
          break;
        case 'qcInfo':
          this.attributeModel.inspectionTemplateName = this._get(rowData, 'name', '');
          this.attributeModel.inspectionTemplateId = this._get(rowData, 'id', '');
          this.attributeModel.inspectionTemplateCode = this._get(rowData, 'code', '');
          break;
        case 'inspectionTemplateInfo':
          if (title === 'global') {
            this.globalConfigModel.apaasTemplateName = rowData.name;
            this.globalConfigModel.apaasTemplateId = rowData.id;
            this.globalConfigModel.apaasTemplateCode = rowData.code;
          } else {
            let f2 = this.templateRepeatFlag(this.inspectionTemplateList, rowData.id);
            if (f2) {
              this.$message({
                type: 'warning',
                message: '模板重复，请重新选择！'
              });
              return;
            }
            let flag2 = this._cloneDeep(this.inspectionTemplateList).every((item) => !item.apaasTemplateName || !item.isDefault);
            rowData.isDefault = flag2 ? true : false;
            this._forEach(this.inspectionTemplateList, (item, idx) => {
              if (title === idx) {
                this.$set(item, 'apaasTemplateName', rowData.name);
                item.apaasTemplateCode = rowData.code;
                item.apaasTemplateId = rowData.id;
                item.isDefault = item.isDefault ? true : rowData.isDefault;
              }
            });
          }
          break;
        default:
          break;
      }
    },
    templateRepeatFlag(list, id) {
      return list.some((item) => item.apaasTemplateId === id);
    },
    /**
     * 打开用户管理选择模态框
     */
    openUserCommonModal(titleInfo) {
      this.modalName = 'userModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择用户管理信息（双击进行选择）',
        url: '/api/blade-system/user/page',
        isPage: true,
        titleInfo,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '用户姓名',
            prop: 'name',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '所属部门',
            prop: 'deptName',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '职务',
            prop: 'postName'
          },
          {
            label: '用户平台',
            prop: 'userTypeName'
          }
        ]
      };
    },
    /**
     * Aql配置信息模态框
     */
    openAqlConfigModal(titleInfo) {
      this.modalName = 'aqlModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: 'AQL配置方案信息（双击进行选择）',
        url: '/api/mes-qms/qms-aql-scheme/page',
        isPage: true,
        titleInfo,
        searchLabelWidth: 130,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: 'AQL配置方案编码',
            prop: 'code',
            search: true,
            disabled: true
          },
          {
            label: 'AQL配置方案名称',
            prop: 'name',
            search: true,
            rules: [{ required: true, message: '请输入AQL配置方案名称', trigger: 'blur' }]
          },
          {
            label: '抽样标准类型',
            prop: 'samplingStandard',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            rules: [{ required: true, message: '请选择抽样标准类型', trigger: 'blur' }]
          },
          {
            label: '严格程度',
            prop: 'severityCode',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_plan',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检验水平',
            prop: 'levelType',
            type: 'select',
            display: true,
            dicUrl: '/api/blade-system/dict/dictionary?code=aql_inspection_level',
            cascader: ['levelCode'],
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            control: (val, form) => {
              if (val == 'SPECIAL') {
                return {
                  levelCode: { dicUrl: '/api/blade-system/dict/dictionary?code=special_inspection_level' }
                };
              } else {
                return {
                  levelCode: { dicUrl: '/api/blade-system/dict/dictionary?code=general_inspection_level' }
                };
              }
            }
          },
          {
            label: '检验水平代码',
            prop: 'levelCode',
            type: 'select',
            display: true,
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            dicData: [
              {
                dictValue: 'Ⅰ',
                dictKey: '1'
              },
              {
                dictValue: 'Ⅱ',
                dictKey: '2'
              },
              {
                dictValue: 'Ⅲ',
                dictKey: '3'
              }
            ]
          },
          {
            label: '质量水平代码',
            prop: 'limitCode',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_code',
            props: {
              label: 'dictKey',
              value: 'dictKey'
            },
            dicFormatter: (data) => {
              return this._map(data.data, (item) => {
                return {
                  ...item,
                  dictKey: item.dictKey
                };
              });
            },
            rules: [
              {
                required: true,
                message: '请选择质量水平代码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '严重缺陷质量代码',
            prop: 'severityLimitCode',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_code',
            props: {
              label: 'dictKey',
              value: 'dictKey'
            },
            hide: true
          },
          {
            label: '主要缺陷质量代码',
            prop: 'majorLimitCode',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_code',
            props: {
              label: 'dictKey',
              value: 'dictKey'
            },
            hide: true
          },
          {
            label: '次要缺陷质量代码',
            prop: 'minorLimitCode',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sample_code',
            props: {
              label: 'dictKey',
              value: 'dictKey'
            },
            hide: true
          },
          {
            label: '是否启用',
            prop: 'enabled',
            type: 'switch',
            value: true,
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          },
          {
            label: '方案描述',
            prop: 'description',
            type: 'textarea',
            hide: true,
            span: 24
          },
          {
            label: '制定人员',
            prop: 'createUserName',
            display: false
          },
          {
            label: '制定时间',
            prop: 'updateTime',
            display: false
          }
        ]
      };
    },
    /**
     * 供应商信息模态框
     */
    openPartnerModal() {
      this.modalName = 'partnerModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择供应商信息（双击进行选择）',
        url: '/api/mes-admin/vendor/page',
        isPage: true,
        index: false,
        rowSelectionType: 'single',
        titleInfo: 'partnerInfo',
        columnDefs: [
          {
            label: '编码',
            prop: 'code',
            search: true
          },
          {
            label: '名称',
            prop: 'name',
            search: true
          },
          {
            label: '缩写',
            prop: 'abbreviation'
          },
          {
            label: '联系人',
            prop: 'principal'
          },
          {
            label: '联系方式',
            prop: 'contacts'
          },
          {
            label: '位置',
            prop: 'locations'
          }
        ]
      };
    },
    /**
     * 检验模板模态框
     */
    openQcModal() {
      this.$refs.commonModalTemplate.showModal();
      this.modalName = 'qcInfo';
      this.tableOption = {
        modalTitle: '选择检验模板（双击进行选择）',
        url: '/api/mes-product/qms-inspection-template/page?type=IQC',
        isPage: true,
        selection: true,
        rowSelectionType: 'single',
        titleInfo: 'qcInfo',
        columnDefs: [
          {
            label: '模板类型',
            prop: 'type',
            minWidth: 150,
            searchOrder: 1
          },
          {
            label: '检验模板名称',
            minWidth: 150,
            search: true,
            searchOrder: 2,
            searchSpan: 8,
            searchLabelWidth: 150,
            prop: 'name'
          },
          {
            label: '检验模板编码',
            prop: 'code',
            minWidth: 100
          },
          {
            label: '版本号',
            minWidth: 100,
            prop: 'revision'
          },
          {
            label: '备注',
            minWidth: 100,
            prop: 'remark'
          },

          {
            label: '制定人',
            prop: 'createUserName'
          },
          {
            label: '制定时间',
            minWidth: 150,
            prop: 'createTime',
            type: 'datetime'
          }
        ]
      };
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-table {
  margin-bottom: 10px;
}
::v-deep .el-table .criterion-select-row {
  background-color: #caf982 !important;
}
.tranfer-dialog {
  ::v-deep .avue-crud__search {
    border: none !important;
  }
  ::v-deep .avue-crud__right {
    display: none !important;
  }

  ::v-deep .avue-crud__pagination {
    position: absolute;
    padding: 25px 0 50px 20px !important;
  }

  ::v-deep .el-dialog__footer {
    margin-top: 65px;
  }
}
.title {
  font-size: 16px;
  font-weight: 600;
}
.el-transfer-button {
  height: 80% !important;
}

.template-style {
  display: flex;
  flex-direction: row;
}
</style>
